const { err, to } = require("../../utils/wxapi");
const api = require("../../api/sop");
Page({
  /**
   * 页面的初始数据
   */
  data: {
    navNumber: 0,
    nav: [
      { title: "未审核", isEntry: 0 },
      { title: "已通过", isEntry: 1 },
      { title: "未通过", isEntry: 2 },
    ],
    page: 1,
    list: [],
    total: 0,
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getlist();
  },
  nav_click(e) {
    const { i } = e.currentTarget.dataset;
    this.setData({ navNumber: i, page: 1 });

    this.getlist();
  },
  async getlist() {
    try {
      const { page, nav, navNumber, list } = this.data;
      const userId = wx.getStorageSync("userId");
      const data = JSON.stringify({
        userId,
        isEntry: nav[navNumber].isEntry,
      });
      const res = await api.entrylist({ page, data });
      if (res.respCode === 200) {
        const newlist = JSON.parse(res.source);
        const total = res.pageTotal;
        const updatelist = page > 1 ? [...list, ...newlist] : newlist;
        console.log(updatelist);
        this.setData({ list: updatelist, total });
      }
    } catch (error) {
      err(error);
    }
  },
  todel(e) {
    const { id } = e.currentTarget.dataset;
    to("/two/enlist/enlist?id=" + id);
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    const { page, total, list } = this.data;
    if (list.length < total) {
      this.setData({ page: page + 1 });
      this.getlist();
    } else {
      toast("暂无更多内容");
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});
